package jdbc;

import model.UserService;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

    @WebServlet(name = "updateUser", value = "/updateUser")
public class UpdateUser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        request.setCharacterEncoding("utf-8");
        String un = request.getParameter("un");
        String pw = request.getParameter("pw");
        String tel = request.getParameter("tel");
        String addr = request.getParameter("addr");
        String id = request.getParameter("id");
        Map<String, String> m = new HashMap<String, String>();
        m.put("id", id);
        m.put("username", un);
        m.put("password", pw);
        m.put("telephone", tel);
        m.put("address", addr);

        int r = new UserService().updateUser(m);
        if (r == 1)  out.print("修改成功");
        else out.print("修改失败");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
